package com.estronger.shopmanage.ui.othertask.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.estronger.shopmanage.R;
import com.estronger.shopmanage.ui.othertask.bean.OtherTaskMainBean;
import com.soonfor.evaluate.base.EvalBaseAdapter;
import com.soonfor.evaluate.tools.CommonUtils;

import java.util.List;

/**
 * Created by DingYg on 2018-01-30.
 */

public class OtherTaskMainAdapter extends EvalBaseAdapter<OtherTaskMainAdapter.ViewHolder, OtherTaskMainBean.DataBean> {

    private List<OtherTaskMainBean.DataBean> list;
    private int type;
    View.OnClickListener listener;

    public OtherTaskMainAdapter(Activity context, int type, View.OnClickListener listener) {
        super(context);
        this.type = type;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.adapter_othertask, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.setData(context, list.get(position), position);

    }

    @Override
    public void notifyDataSetChanged(List<OtherTaskMainBean.DataBean> dataList) {
        this.list = dataList;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

     class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvfTaskTitle;//任务类型
        TextView tvfName;//客户姓名和性别
        TextView tvfBuilding;//楼盘
        TextView tvfTimeT;//执行时间（或完成时间）
        TextView tvfExecuteTime;//执行时间

        TextView tvfWorkpoints;//工分
        LinearLayout llfItem;//item整体

        Button btnUpdateTaskResult;//更新任务结果
        Button btnLookDisDetail;//查看处理详情
        TextView tvfStatus;//状态类型


        public ViewHolder(View itemView) {
            super(itemView);
            this.tvfTaskTitle = itemView.findViewById(R.id.tvfTaskTitle);
            this.tvfName = itemView.findViewById(R.id.tvName);
            this.tvfBuilding = itemView.findViewById(R.id.tvfBuilding);
            this.tvfTimeT = itemView.findViewById(R.id.tvfTiemTitle);
            this.tvfExecuteTime = itemView.findViewById(R.id.tvfExecuteDate);

            this.tvfWorkpoints = itemView.findViewById(R.id.tvfWorkpoints);
            this.llfItem = itemView.findViewById(R.id.llfItem);


            btnLookDisDetail = itemView.findViewById(R.id.btnLookDisDetail);
            btnUpdateTaskResult = itemView.findViewById(R.id.btnUpdateTaskResult);
            tvfStatus = itemView.findViewById(R.id.tvftypes);
        }

        public void setData(Context mContext, OtherTaskMainBean.DataBean gpBean, int position) {
            this.tvfTaskTitle.setText(gpBean.getFtitle());
            tvfStatus.setText(gpBean.getFprocstatedesc());
            CommonUtils.setSex(this.tvfName,gpBean.getFcname(),gpBean.getFsexdesc());
            this.tvfBuilding.setText(gpBean.getFbuildname());
            this.tvfExecuteTime.setText(gpBean.getFplantime() + gpBean.getFplantime2() );
            this.tvfWorkpoints.setText(gpBean.getFpoint());
            this.llfItem.setTag(position);
            this.tvfName.setTag(position);
            this.llfItem.setOnClickListener(listener);
            this.tvfName.setOnClickListener(listener);
            //Item底部的按钮

            if(gpBean.getFprocstatedesc().contains("完成")|| gpBean.getFprocstatedesc().contains("已邮寄")){
                btnLookDisDetail.setVisibility(View.VISIBLE);
                btnUpdateTaskResult.setVisibility(View.GONE);
                tvfTimeT.setText("完成时间：");
                this.btnLookDisDetail.setTag(position);
                this.btnLookDisDetail.setOnClickListener(listener);
            }else {
                btnLookDisDetail.setVisibility(View.GONE);
                btnUpdateTaskResult.setVisibility(View.VISIBLE);
                tvfTimeT.setText("执行时间：");
                this.btnUpdateTaskResult.setTag(position);
                this.btnUpdateTaskResult.setOnClickListener(listener);
            }
        }
    }
}
